package vlms.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import vlms.bean.Person;
import vlms.bean.PremiumCustomer;
import vlms.bean.SimpleCustomer;
import vlms.service.VLMSServiceProxy;

/**
 * Servlet implementation class DisplayAllPremiumCustomers
 */
public class DisplayAllPremiumCustomers extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DisplayAllPremiumCustomers() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		VLMSServiceProxy proxy = new VLMSServiceProxy();  
		proxy.setEndpoint("http://localhost:8080/VLMS/services/VLMSService");
		Person[] personList=null;
		
		PremiumCustomer[] premiumCustomerList=null;
		try
		{
			System.out.println("called..");
			personList=proxy.listAllPersons();
			
			premiumCustomerList=proxy.listPremiumCustomer();
			request.setAttribute("PersonList", personList);
			
			request.setAttribute("PremiumCustomer", premiumCustomerList);
			
			RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/displayAllPremiumCust.jsp");
			dispatcher.forward(request, response);

		}
		catch(Exception e)
		{
			String message=e.getMessage();
			e.printStackTrace();
			request.setAttribute("message", message);
			RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/adminHome.jsp");
			dispatcher.forward(request, response);
		}

	}

}
